<template>
  <div>
    <el-table
      v-loading="listLoading"
      :key="tableKey"
      :data="list"
      element-loading-text="给我一点时间"
      border
      fit
      highlight-current-row
      style="width: 100%">
      <el-table-column width="80" align="center" label="消防设施图像">
        <template slot-scope="scope">
          <embed :src="scope.row.assetimageurl" style="height:auto;width:100%;">
        </template>
      </el-table-column>
      <el-table-column width="200" align="center" label="消防设施名称">
        <template slot-scope="scope">
          <span>{{ scope.row.assetname }}</span>
        </template>
      </el-table-column>
      <el-table-column width="130" align="center" label="消防设施类型ID">
        <template slot-scope="scope">
          <span>{{ scope.row.moduleid }}</span>
        </template>
      </el-table-column>
      <el-table-column width="130" align="center" label="消防设施ID">
        <template slot-scope="scope">
          <span>{{ scope.row.assetid }}</span>
        </template>
      </el-table-column>
      <el-table-column width="130" align="center" label="绑定时间">
        <template slot-scope="scope">
          <span>{{ scope.row.createtime }}</span>
        </template>
      </el-table-column>

      <el-table-column :label="$t('table.actions')" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="handleMeasure(scope.row)">{{ $t('table.measurements') }}</el-button>
        </template>
      </el-table-column>

    </el-table>

    <div class="pagination-container">
      <el-pagination
        :current-page.sync="listQuery.page"
        :page-sizes="[10,20,30, 50]"
        :page-size="listQuery.pagesize"
        :total="total"
        background
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
  </div>
</template>

<script>

import { bindfacilList } from '@/api/fire/asset/asset'
import waves from '@/directive/waves' // 水波纹指令

export default {
  name: 'FaciAssignmentList',
  directives: {
    waves
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: null,
      listLoading: true,
      listQuery: {
        page: 1,
        pagesize: 10,
        assetname: '',
        siteid: '',
        arange: this.$route.name
      },
      showReviewer: false,
      textMap: {

      },
      btn_query: false,
      btn_add: false,
      btn_edit: false,
      btn_delete: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      bindfacilList(this.listQuery).then(response => {
        console.log(response)
        this.list = response.data.context.assignedlists
        this.total = response.data.context.total
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.pagesize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    handleMeasure(row) {
      this.$router.push({
        path: '/asset/measure',
        name: 'measure',
        params: {
          'assetid': row.assetid
        }
      })
    },
    handleModifyStatus(row, status) {
      this.$message({
        message: '操作成功',
        type: 'success'
      })
      row.status = status
    }
  }
}
</script>

